package zwp.exercise.service.exercisedemo.chapterFour;

/**
 * @Author zwp14
 * @create 2025/11/24 22:00
 * @description 蜗牛爬井练习题
 * 井深10米，一只蜗牛从井底开始爬，蜗牛速度是：白天爬两米，晚上下滑一米，问多少天可以爬出井口
 */
public class SnailClimbsTheWellExerciseDemo {
    public static void main(String[] args) {
        // 使用while循环
        methodOne();
        // 使用while循环+break
        methodTwo();
    }

    private static void methodTwo() {
        int snailDeep = 10;
        int finalDeep = 0;
        int finalDays = 0;

        while (true) {
            finalDeep += 2;
            finalDeep -= 1;
            finalDays += 1;

            if (finalDeep == snailDeep) {
                break;
            }
        }

        System.out.println("蜗牛在" + finalDays + "天后，将会爬出井口！");
    }

    private static void methodOne() {
        int snailDeep = 10;
        int finalDeep = 0;
        int finalDays = 0;
        do {
            // 白天爬2米
            finalDeep += 2;
            // 晚上下滑1米
            finalDeep -= 1;
            finalDays += 1;
        } while (finalDeep < snailDeep);
        System.out.println("蜗牛在" + finalDays + "天后，将会爬出井口！");
    }
}
